package dao

import (
	"fmt"
	"yun_image/entity"
	"yun_image/util"
)

var (
	apiAccess []entity.ApiAccess
)

// 从数据库中获取所有的api权限，用于验证权限
func pullAllApiAccess() error {
	result := DB.Find(&apiAccess)
	if result.Error != nil {
		fmt.Println(util.Red("apiAccess同步失败！！"))
		return result.Error
	}
	fmt.Println(util.Green("apiAccess同步成功"))
	return nil
}

func GetApiPathsByRoleId(apiPaths *[]string, roleId int) error {
	var paths []string
	for _, value := range apiAccess {
		if roleId == value.RoleId {
			paths = append(paths, value.ApiPath)
		}
	}
	*apiPaths = paths
	return nil
}
